home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / pmpsrc11.zip / LEVEL2TX.C < prev    next >
Text File  |  1991-07-30  |  2KB  |  86 lines

  1. /*
  2.     level2tx.c -- Level 2 transmit routines for PMP
  3.  
  4.   Poor Man's Packet (PMP)
  5.   Copyright (c) 1991 by Andrew C. Payne    All Rights Reserved.
  6.  
  7.   Permission to use, copy, modify, and distribute this software and its
  8.   documentation without fee for NON-COMMERCIAL AMATEUR RADIO USE ONLY is hereby
  9.   granted, provided that the above copyright notice appear in all copies.
  10.   The author makes no representations about the suitability of this software
  11.   for any purpose.  It is provided "as is" without express or implied warranty.
  12.  
  13.     Andrew C. Payne
  14. */
  15. /* ----- Includes ------ */
  16. #include <stdio.h>
  17. #include <alloc.h>
  18. #include <mem.h>
  19. #include "pmp.h"
  20.  
  21. /* SendAX25(packet)
  22.     Given an AX25 packet, puts converts it to a byte stream and
  23.     puts it into the TXQueue.
  24.  
  25.     Returns TRUE if error.
  26. */
  27. int SendAX25(struct ax25_packet *p)
  28. {
  29.     struct ax25_level1    *t;        /* byte stream */
  30.     byte    *q;                /* temp pointer */
  31.     int    i;                /* counter */
  32.     int    data;
  33.  
  34. /* compute length of byte stream and allocate space */
  35.     i = sizeof(struct ax25_addr)*2
  36.             + 3 + p->ndigis * 7 + p->dlen;
  37.  
  38. /* find frame type */
  39.     switch(FrameType(p->cont)) {
  40.         case I:
  41.         case UI:
  42.             data = TRUE;
  43.             i++;            /* needs PID byte */
  44.             break;
  45.         default:
  46.             data = FALSE;
  47.     }
  48.  
  49.     t = malloc(i + sizeof(struct ax25_level1));
  50.     t->len = i;
  51.  
  52. /* copy destination and source addresses into packet */
  53.     memcpy(q = t->data,&p->dest,sizeof(struct ax25_addr));
  54.     memcpy(q += sizeof(struct ax25_addr),&p->source,sizeof(struct ax25_addr));
  55.  
  56. /* set command/response mode */
  57.     if(p->cmdresp == COMMAND)
  58.         t->data[MAXCLEN] |= 0x80;
  59.     else
  60.         t->data[MAXCLEN + sizeof(struct ax25_addr)] |= 0x80;
  61.  
  62. /* copy digipeater path in, if necessary */
  63.     q += sizeof(struct ax25_addr);
  64.     if(p->ndigis) {
  65.         for(i=0; i<p->ndigis; i++) {
  66.             memcpy(q,&p->digis[i],sizeof(struct ax25_addr));
  67.             q += sizeof(struct ax25_addr);
  68.         }
  69.     }
  70.  
  71. /* set the address extension bit on the last address byte */
  72.     q[-1] |= 1;
  73.  
  74. /* copy in the control */
  75.     *q++ = p->cont;
  76.  
  77. /* copy in the PID & data field, if I or UI packet */
  78.     if(data) {
  79.         *q++ = p->pid;
  80.         memcpy(q,p->data,p->dlen);
  81.     }
  82.  
  83. /* add the packet to the TX Queue */
  84.     return TXQAdd(t);
  85. }
  86.